package com.example.demo.common;

import com.example.demo.entity.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author :蕉绿
 * @Date : 2023/3/16 19:16
 * @Version : V1.0
 * @Description :
 */

//和当前登陆用户相关的操作
public class UserSessionUtils {

    //得到当前的登陆用户
    public static Userinfo getSessionUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session!=null && session.getAttribute(AppVariable.USER_SESSION_KEY)!=null){
            //说明已经正常登录
            return  (Userinfo) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return null;
    }

}
